/**
 * @file /include/rp_ui/qnode.hpp
 *
 * @brief Communications central!
 *
 * @date February 2011
 **/
/*****************************************************************************
** Ifdefs
*****************************************************************************/

#ifndef rp_ui_QNODE_HPP_
#define rp_ui_QNODE_HPP_

/*****************************************************************************
** Includes
*****************************************************************************/

#include <ros/ros.h>
#include <string>
#include <QThread>
#include <QStringListModel>

#include "topic/topic.h"
#include "comm/ears_msg.h"
#include "comm/emotion_msg.h"
#include "comm/eyebrows_msg.h"
#include "comm/gripper_msg.h"
#include "comm/trunk_msg.h"


/*****************************************************************************
** Namespaces
*****************************************************************************/

namespace rp_ui {

/*****************************************************************************
** Class
*****************************************************************************/

class QNode : public QThread {
    Q_OBJECT
public:
	QNode(int argc, char** argv );
	virtual ~QNode();
	bool init();
	bool init(const std::string &master_url, const std::string &host_url);
	void run();

	// subscribe to all the topics for Ollie
	void subscribeTopics();

	/**
	 * Setters for motor topics.
	 */
	void sendTrunk(int msg);
	void sendGripper(int msg);
	void sendEyebrows(int msg);
	void sendEars(int msg);
signals:
    void rosShutdown();

	/**
	 * Update signals. The GUI will catch these signals and update the values.
	 */
	void trunkUpdated(int state);
	void gripperUpdated(int state);
	void eyebrowsUpdated(int state);
	void earsUpdated(int state);

protected:
	ros::Publisher trunk_pub;
	ros::Publisher gripper_pub;
	ros::Publisher eyebrows_pub;
	ros::Publisher ears_pub;

	ros::Subscriber trunk_sub;
	ros::Subscriber gripper_sub;
	ros::Subscriber eyebrows_sub;
	ros::Subscriber ears_sub;

    /**
     * Callbacks
     */
	void trunkCallback(const comm::trunk::ConstPtr &msg);
	void gripperCallback(const comm::gripper::ConstPtr &msg);
	void eyebrowsCallback(const comm::eyebrows::ConstPtr &msg);
	void earsCallback(const comm::ears::ConstPtr &msg);

private:
	int init_argc;
	char** init_argv;
};

}  // namespace rp_ui

#endif /* rp_ui_QNODE_HPP_ */
